$(document).ready(function(){
	var dateToday = new Date();
	var dates = $("#test_start_date, #test_end_date").datepicker({
    			defaultDate: "",
    			changeMonth: false,
    			numberOfMonths: 1,
    			minDate: dateToday,
    			onSelect: function(selectedDate) {
        					var option = this.id == "test_start_date" ? "minDate" : "maxDate",
            					instance = $(this).data("datepicker"),
            					date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
        					dates.not(this).datepicker("option", option, date);
    					}
				});
	$('#adv-settings-opt').click(function(){
		console.log("here");
		var one = $(this).find('#show-adv-text');
		if($('#adv-sett-toggle').find(".sectionarrow").hasClass("rotate"))
		{		
			one.html('<span id="show-adv-text"><span id="adv-sett-toggle"><img src="images/arrow-small.png" class="sectionarrow" /></span>Advanced Settings</span>');
			$('#adv-sett').slideDown();
		}
		else
		{
			one.html('<span id="show-adv-text"><span id="adv-sett-toggle"><img src="images/arrow-small.png" class="sectionarrow rotate" /></span>Advanced Settings </span>');
			$('#adv-sett').slideUp();
		}
	});
	var counter = 1;
	var question_area = '';
	var question_template_1 = '';
	var question_template_2 = '';
	var question_template_3 = '';
	var question_template_4 = '';
	var question_template_5 = '';
	var question_template_6 = '';
	//modified t/f
	//regular t/f
	//short answer
	//multiple choice
	//matching(later)
	//many choice (will be great if we implement this)
	//essay (will be graded by teacher)
	//assign default points if points possible not provided by teacher (per question basis)
		//2 points for t/f, if false, check if correct phrase or word is in answer and flag test as needing attention
		//2 points for short answer
		//1 default <-----multipe choice
		//essay (has to be supplied by teacher)
	$('#question_template_tf_div').html('').hide();
	$('#question_template_mod_tf_div').html('').hide();
	$('#question_template_short_ans_div').html('').hide();
	$('#question_template_matching_div').html('').hide();
	$('#question_template_multi_choice_div').html('').hide();
	$('#question_template_essay_div').html('').hide();
	$('#question_template_many_choice_div').html('').hide();
	var p_non_zero = new RegExp(/^[1-9][0-9]*$/);
	$('#single-day-container').click(function () {
		if(!$("#single-day-check").is(':checked'))
		{
    		$("#single-day-check").prop('checked', true);
    		$('#end-date-area').hide();
    	}
    	else
    	{
    		$("#single-day-check").prop('checked', false);
    		$('#end-date-area').show();
    	}
	});
	$('#single-day-check').click(function () {
		if(!$("#single-day-check").is(':checked'))
		{
    		$("#single-day-check").prop('checked', true);
    		$('#end-date-area').hide();
    	}
    	else
    	{
    		$("#single-day-check").prop('checked', false);
     		$('#end-date-area').show();
    	}
	});
	//check for positive, integers only for test time; regex already done
	$('#test-limit, #test-limit-container').click(function(){
		$('#test-limit').focus();
		$('#test-limit').keyup(function(){
			var string = $(this).val();
			if(p_non_zero.test(string))
				$(this).val(string);
			else
			{
				string = string.replace(/,/g, "");
				string = string.replace(/-/g, "");
				string = string.replace(/^[0]+/g, "");
				string = string.replace(/./g,"");
				$(this).val(string);
			}
			console.log(p_non_zero.test(string));
			console.log(string);

		});
	});
	$('#adv-settings-opt, #adv-sett-1').click(function(){
		$('#num-questions').focus();
		$('#num-questions').keyup(function(){
			var string = $(this).val();
			if(p_non_zero.test(string))
				$(this).val(string);
			else
			{
				string = string.replace(/,/g, "");
				string = string.replace(/-/g, "");
				string = string.replace(/^[0]+/g, "");
				string = string.replace(/./g,"");
				$(this).val(string);
			}
			console.log(p_non_zero.test(string));
			console.log(string);

		});
	});
	$('#adv-sett-2').click(function(){
		$('#num-points').focus();
		$('#num-points').keyup(function(){
			var string = $(this).val();
			if(p_non_zero.test(string))
				$(this).val(string);
			else
			{
				string = string.replace(/,/g, "");
				string = string.replace(/-/g, "");
				string = string.replace(/^[0]+/g, "");
				string = string.replace(/./g,"");
				$(this).val(string);
			}
			console.log(p_non_zero.test(string));
			console.log(string);

		});
	});
	$('#adv-sett-3').click(function(){
		if(!$('#shuffle-check').is(':checked'))
			$('#shuffle-check').prop('checked', true);
		else
			$('#shuffle-check').prop('checked', false);
	});
	$('#shuffle-check').click(function(){
		if(!$('#shuffle-check').is(':checked'))
			$('#shuffle-check').prop('checked', true);
		else
			$('#shuffle-check').prop('checked', false);
	});
});